Skip to content

fix(files): use incremental applyEdits to prevent streaming flicker in Monaco editor#4347

Merged
waleedlatif1 merged 4 commits intostagingfrom
fix/color-text
Apr 30, 2026
Merged

fix(files): use incremental applyEdits to prevent streaming flicker in Monaco editor#4347
waleedlatif1 merged 4 commits intostagingfrom
fix/color-text

Conversation

@waleedlatif1
Copy link
Copy Markdown
Collaborator

Summary

  • Replace model.setValue() with model.applyEdits() when syncing streamed content into the Monaco editor during Mothership file generation
  • When content is purely additive (each chunk is a superset of the previous), only insert the new suffix — no re-tokenization of existing content, no scroll/selection reset
  • Fall back to a full-range applyEdits for non-additive changes (e.g. patch operations)
  • Remove the now-unnecessary saveViewState/restoreViewState pair — applyEdits preserves scroll and cursor state natively

Type of Change

  • Bug fix

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 29, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Apr 30, 2026 0:30am

Request Review

@cursor
Copy link
Copy Markdown

cursor Bot commented Apr 29, 2026

PR Summary

Medium Risk
Touches Monaco content synchronization during streaming, which can subtly affect cursor/scroll behavior and correctness of incremental updates, but is limited in scope and not security-sensitive.

Overview
Reduces flicker and preserves cursor/scroll position when syncing streamed file generation output into the Monaco editor by replacing model.setValue() with model.applyEdits().

When incoming content is purely additive, the editor now inserts only the new suffix at the end; otherwise it falls back to replacing the full model range, and removes the previous view-state save/restore workaround.

Reviewed by Cursor Bugbot for commit 1b76937. Configure here.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 29, 2026

Greptile Summary

This PR replaces model.setValue() with incremental model.applyEdits() in the Monaco editor's streaming sync effect to eliminate scroll/cursor flicker during Mothership file generation. The additive path correctly anchors against monacoValue (the live model snapshot) rather than lastSyncedContentRef.current, avoiding the stale-ref invariant from the previous round. The saveViewState/restoreViewState pair is correctly dropped since applyEdits preserves view state natively, and using applyEdits (vs. the earlier pushEditOperations) keeps streamed chunks out of the undo stack.

Confidence Score: 5/5

Safe to merge — targeted, well-reasoned fix with no new regressions introduced.

The change is small and focused. The two previously-raised P1 concerns (stale-ref invariant and undo-stack pollution) are both resolved in the final commit. The additive path correctly uses the live monacoValue snapshot, applyEdits bypasses the undo stack as intended, and removal of the save/restore view state pair is correct since applyEdits preserves scroll position natively. No P0 or P1 issues remain.

No files require special attention.

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/text-editor.tsx Streaming sync effect rewritten to use incremental applyEdits; additive detection uses live monacoValue; undo-stack concern addressed. No new issues found.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Effect fires: content changed or isStreamInteractionLocked changed] --> B{monacoValue === content?}
    B -- Yes --> C[Early return — no-op]
    B -- No --> D{isStreamInteractionLocked OR monacoValue === lastSyncedContentRef?}
    D -- No --> C2[Skip sync — user is actively editing]
    D -- Yes --> E[Capture scroll-stuck state]
    E --> F[suppressScrollListener = true]
    F --> G{content.startsWith monacoValue AND monacoValue shorter?}
    G -- Yes: additive --> H[applyEdits: insert suffix at end of last line]
    G -- No: non-additive --> I[applyEdits: replace full model range]
    H --> J[suppressScrollListener = false]
    I --> J
    J --> K[lastSyncedContentRef = content]
Loading

Reviews (3): Last reviewed commit: "fix(files): revert to applyEdits to avoi..." | Re-trigger Greptile

Comment thread apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/text-editor.tsx Outdated
@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

Comment thread apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/text-editor.tsx Outdated
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 00ef26b. Configure here.

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 1b76937. Configure here.

@waleedlatif1 waleedlatif1 merged commit 6081670 into staging Apr 30, 2026
14 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/color-text branch April 30, 2026 00:41
@waleedlatif1 waleedlatif1 restored the fix/color-text branch April 30, 2026 02:17
waleedlatif1 added a commit that referenced this pull request Apr 30, 2026
…n Monaco editor (#4347)

* fix(files): use incremental applyEdits to prevent streaming flicker in Monaco editor

* fix(files): use actual model value for additive applyEdits guard

* fix(files): use pushEditOperations instead of applyEdits to align with VS Code streaming pattern

* fix(files): revert to applyEdits to avoid polluting undo stack during streaming
@waleedlatif1 waleedlatif1 deleted the fix/color-text branch April 30, 2026 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant